package com.summer.Map;

import java.util.*;

public class HashMapTest {
    //HashMap 线程不安全 效率高
    public static void main(String[] args) {
        Map map = new HashMap();//jdk 7 数组+链表  jdk8 数组+链表+红黑树
        Map map1 = new LinkedHashMap();//添加了一个双向指针
        map.put("AA",123);
        map.put("BB",456);
        map.put("CC",789);
        map.put(45,123);
        System.out.println(map);
        map1.put("DD",145);
        map1.put("EE",451);
        map1.put("FF",765);
        map.putAll(map1);
        System.out.println(map);
        map.remove("AA");
        System.out.println(map.containsKey("DD"));
        System.out.println(map.containsValue(123));
        Set set = map.keySet();
        //Collection values = map.values();
        Iterator iterator = set.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
        //遍历 kry-values
        Set set1 = map.entrySet();
        Iterator iterator1 = set1.iterator();
        while (iterator1.hasNext()){
            Object next = iterator1.next();
           Map.Entry entry =  (Map.Entry) next;
            System.out.println(entry.getKey()+"---"+entry.getValue());
        }
        map.clear();

    }
}
